//package com.endbd.systemmanagement.aspect;
//
//import com.endbd.feignapi.annotation.SystemLog;
//import com.endbd.feignapi.annotation.SystemLogEnum;
//import com.endbd.feignapi.model.system.Journal;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.After;
//import org.aspectj.lang.annotation.AfterThrowing;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.messaging.support.MessageBuilder;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.Date;
//
//
//@Aspect
//@Slf4j
//public class SystemLogAspect {
//
//  @Autowired
//  private MyStream stream;
//
//  @Pointcut("@annotation(com.endbd.feignapi.annotation.SystemLog)")
//  public void logPointCut(){}
//
//  @After("logPointCut()")
//  public void afterLog(JoinPoint joinPoint) {
//    //一般日志
//    Journal journal = wrapJournal(joinPoint);
//
//    log.info("Log值："+journal);
//
//    //发送mq消息
////    stream.logOutput().send(MessageBuilder.withPayload(journal).build());
//
//  }
//
//  //异常通知
//
//  @AfterThrowing(value = "logPointCut()", throwing = "e")
//  public void throwingLog(JoinPoint joinPoint, Exception e) {
//    //异常日志
//    Journal journal = wrapJournal(joinPoint);
//
//    log.info("异常Log值："+e);
//
//    //发送mq消息
////    stream.logOutput().send(MessageBuilder.withPayload(journal).build());
//  }
//
//  private Journal wrapJournal(JoinPoint joinPoint) {
//    Journal journal = new Journal();
//
//    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//    assert attributes != null;
//    HttpServletRequest request = attributes.getRequest();
////    Integer uId = Integer.valueOf(request.getHeader("uId"));
////    Integer moduleId = Integer.valueOf(request.getHeader("moduleId"));
//
//    MethodSignature signature = (MethodSignature)joinPoint.getSignature();
//    SystemLog systemLog = signature.getMethod().getAnnotation(SystemLog.class);
//    SystemLogEnum type = systemLog.type();
//    if("insert".equals(type.getType())){
//      journal.setJContent("新增加了一条数据");
//    }else if("update".equals(type.getType())){
//      journal.setJContent("修改了一条数据");
//    }else if("delete".equals(type.getType())){
//      journal.setJContent("删除了一条数据");
//    }
//
////    journal.setUId(uId);
////    journal.setModuleId(moduleId);
//    journal.setJDate(new Date());
//
//    return journal;
//  }
//
//
//}
